#!/bin/bash
. ./var
. ./Tmpdir
redis(){
    redis_version="redis-5.0.8.tar.gz"
    TAR_version="redis-5.0.8"

    #调用Tmpdir函数
    Tmpdir
    cd $dir && wget -V &> /dev/null || yum -y install wget
    redis-server -v &> /dev/null && echoRed "检测到系统中有redis-server命令，故而退出！" && rm -rf $dir && exit 1
    which redis-server &&  which redis-cli
    if [ $? = 0 ];then
        echoGreen "检测到系统中有redis-server和redis-cli命令，故而退出！"
        rm -rf $dir
        exit 6
    else
        #wget http://download.redis.io/releases/redis-5.0.8.tar.gz
        wget $ip/${redis_version} && yum -y install gcc gcc-c++ && tar -xf ${redis_version} && cd ${TAR_version} && make && make install
        if [ $? = 0 ];then
            echoGreen "redis编译安装成功，即将修改配置文件"
            sed -i '136s/no/yes/g' redis.conf && sed -i '166s/notice/warning/g' redis.conf && sed -i '171s|logfile.*|logfile "/usr/local/redis/redis-6379.log"|g' redis.conf  && mv $dir/${TAR_version} /usr/local/redis
            
            echoGreen "正在启动redis……"
            sleep 6  
            /usr/local/redis/src/redis-server /usr/local/redis/redis.conf && echoGreen "已完成安装并启动了redis，请尽情享用！" || echoYellow "可能安装有问题，请检查！" 
            rm -rf $dir
        else
            echoRed "redis编译安装失败，即将退出"
            rm -rf $dir
            exit 12
        fi
    fi
}
